package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: hp
 * Date: 2024-03-11
 * Time: 22:48
 */
public class AddOperation implements IOperation{
    public void work(BookList bookList) {
        System.out.println("...新添图书...");
        if(bookList.isFull()) {
            System.out.println("图书满了，不能增加！");
            return;
        }
        System.out.print("请输入书名：");
        Scanner scanner = new Scanner(System.in);
        String bookName = scanner.nextLine();

        System.out.print("请输入作者：");
        String authorName = scanner.nextLine();

        System.out.print("请输入类型：");
        String bookType = scanner.nextLine();

        System.out.print("请输入价格：");
        double bookPrice = scanner.nextDouble();


        Book book = new Book(bookName,authorName,bookPrice,bookType);
        int currentSize = bookList.getUseSize();

        bookList.setBook(currentSize,book);
        bookList.setUseSize(currentSize+1);
        System.out.println();
        System.out.println("增加图书成功！");
    }
}
